﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.IO;
using System.Text.RegularExpressions;
using System.Configuration;

namespace NetManager_Server
{
    public partial class FormTimKiem : Form
    {
        public FormTimKiem()
        {
            InitializeComponent();
        }
        private void FormTimKiem_Load(object sender, EventArgs e)
        {

        }
        ket_noi kn = new ket_noi();
        private DataTable thongtin;
        private void doc_thongtin()
        {
            string lenh = "select * from tinhtrang";
            thongtin = function.Doc_bang(lenh);
        }
        private void doc_stt()
        {
            stt.DisplayMember = "stt";
            stt.ValueMember = "stt";
            stt.DataSource = thongtin;
        }
        private void doc_tenmay()
        {
            tenmay.DisplayMember = "tenmay";
            tenmay.ValueMember = "tenmay";
            tenmay.DataSource = thongtin;
        }
        private void timkiem_TextChanged(object sender, EventArgs e)
        {
            if (timkiem.Text != "")
            {
                this.lbtimkiem.Text = "";
            }
        }

        private void bttimkiem_Click(object sender, EventArgs e)
        {
            if (tabnhanvien.Focus())
            {
                if (timkiem.Text == "")
                {
                    this.lbtimkiem.Text = "Vui lòng nhập thông tin tìm kiếm !";
                    timkiem.Focus();
                }
                else
                {
                    kn.Open();
                    SqlDataAdapter tk = new SqlDataAdapter("select manv[Mã NV], hoten[Họ tên], diachi[Địa chỉ], phone[SĐT], email[Email] from NHANVIEN where manv like N'%" + timkiem.Text + "%' or hoten like N'%" + timkiem.Text + "%' or diachi like N'%" + timkiem.Text + "%' or phone like N'%" + timkiem.Text + "%'", kn.conn);
                    DataSet dtstk = new DataSet();
                    tk.Fill(dtstk);
                    kn.Close();
                    view.DataSource = dtstk.Tables[0];
                }
            }
        }

        private void btthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (tabthongtin.Focus())
            {
                if (tenmay.Text == "")
                {
                    this.lbthongtin.Text = "Vui lòng chọn máy để tìm kiếm !";
                    tenmay.Focus();
                }
                else
                {
                    kn.Open();
                    SqlDataAdapter tk = new SqlDataAdapter("select tenmay[Tên máy], ngaybatdau[Ngày bắt đầu], ngayketthuc[Ngày kết thúc], tinhtrang[Tình trạng], ghichu[Ghi chú] from TINHTRANG where stt = '"+stt.Text+"'", kn.conn);
                    DataSet dtstk = new DataSet();
                    tk.Fill(dtstk);
                    kn.Close();
                    view.DataSource = dtstk.Tables[0];
                }
            }
        }

        private void tenmay_TextChanged(object sender, EventArgs e)
        {
            if (tenmay.Text != "")
            {
                this.lbthongtin.Text = "";
            }
        }

        private void tenmay_DropDown(object sender, EventArgs e)
        {
            doc_thongtin();
            doc_stt();
            doc_tenmay();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
